// 在线信息
// by indraw 2013.02.01
package bbs

import (
    //"fmt"
    "strconv"
    "time"
    //"utils/mgo"
    "utils/mgo/bson"
    //"utils/util"
    //"regexp"
	//"encoding/hex"

)

//用户类型
type Online struct{
    Dao
    OnlineData
}

//定义用户信息
type OnlineData struct {
    //
    Userid string         //登录ID
    Username string         //用户姓名
    Groupid    string         //用户群组
    Hidden    string         //

}

/**
 * 初始化对象
 *
 * author: indraw
 * date: 2013-02-11
 */
func newOnline() *Online {

    u := &Online{
        Dao{
            c:db.C("session"),
        },
        OnlineData{
            Userid:"",         //登录ID
            Username:"",         //用户姓名
            Groupid:"",         //用户群组
            Hidden:"",         //
 
        },
    }
    return u
}

/**
 * 获取前多少条记录
 *
 * author: indraw
 * date: 2013-02-11
 */
func (g *Online) top() []OnlineData {
    //fmt.Println("user.go")
    var l []OnlineData
    g.c.Find(nil).Sort("order").Select(bson.M{"userid":1,"username":1,"groupid":1}).All(&l)

    return l
    
}

/**
 * 删除一条记录
 *
 * author: indraw
 * date: 2013-02-11
 */
func (g *Online) deleteByUser() error {
    //fmt.Println("user.go")
    g.c.Remove(bson.M{"userid": g.Userid})
	
    return nil
}

/**
 * 删除一条记录
 *
 * author: indraw
 * date: 2013-02-11
 */
func (g *Online) deleteByTime() error {
    //fmt.Println("user.go")
	
	limit := time.Now().Unix() - 60*10
    limit2 := strconv.FormatInt(limit,10)
    g.c.Remove(bson.M{"s_time": bson.M{"$lt":limit2}})

    return nil
}



















